﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AbstractFactoryName
{
    //抽象工厂
    public abstract class AbstractFactory
    {
        public abstract ShapeBase GetShape(ShapeType shapeType );
        public abstract ColorBase GetColor(ColorType colorType );
    }

    #region 继承抽象工厂

    public class ShapeFactory : AbstractFactory
    {
        public override ColorBase GetColor(ColorType colorType)
        {

            throw new NotImplementedException();
        }

        public override ShapeBase GetShape(ShapeType shapeType)
        {
            ShapeBase shape = null;
            switch (shapeType)
            {
                case ShapeType.Circle:
                    shape = new CircleSharp();
                    break;
                case ShapeType.Square:
                    shape = new SquareSharp();
                    break;
                case ShapeType.Rectangle:
                    shape = new RectangleShape();
                    break;
                default:
                    break;
            }
            return shape;
        }
    }

    public class ColorFactory : AbstractFactory
    {
        public override ColorBase GetColor(ColorType colorType)
        {
            ColorBase color = new ColorBase();
            switch (colorType)
            {
                case ColorType.Red:
                    color = new Red();
                    break;
                case ColorType.Green:
                    color = new Green();
                    break;
                case ColorType.Blue:
                    color = new Blue();
                    break;
                default:
                    break;
            }
            return color;
        }

        public override ShapeBase GetShape(ShapeType shapeType)
        {
            throw new NotImplementedException();
        }
    }

    #endregion

    //实现抽象类的方法

    public class Factory 
    {
        public AbstractFactory  Shape { get;  set; }
        public AbstractFactory Color { get; set; }
        public Factory()
        {

        }

        public ColorShape CreateColorShape(ColorType color,ShapeType shapeType)
        {
            ColorShape colorShape = new ColorShape();
            if (Shape!=null)
            {
                colorShape.CurShape = Shape.GetShape(shapeType);
            }
            if (Color!=null)
            {
                colorShape.CurColor = Color.GetColor(color);
            }
            return colorShape;
        }
    }

    #region 图形
    public class ShapeBase
    {
        public string Name { get; set; }
        public  virtual void Draw()
        {
            throw new NotImplementedException();
        }
    }

    public class CircleSharp: ShapeBase
    {
        public CircleSharp()
        {
            this.Name = "圆形";
        }
    }

    public class SquareSharp : ShapeBase
    {
        public SquareSharp()
        {
            this.Name = "正方形";
        }
    }

    public class RectangleShape:ShapeBase
    {
        public RectangleShape()
        {
            this.Name = "长方形";
        }
    }

    public enum ShapeType
    {
        Circle,
        Square,
        Rectangle,
    }
    #endregion


    #region 颜色
    public class ColorBase
    {
        public string  ColorName { get; set; }
    }

    public class Red : ColorBase
    {
        public Red()
        {
            this.ColorName = "红色";
        }
    }

    public class Green:ColorBase
    {
        public Green()
        {
            this.ColorName = "绿色";
        }
    }

    public class Blue : ColorBase
    {
        public Blue()
        {
            this.ColorName = "绿色";
        }
    }

    public enum ColorType
    {
        Red,
        Green,
        Blue,

    }
    #endregion

    #region 彩色图形

    public class ColorShape
    {
        public ColorBase CurColor { get; set; }
        public ShapeBase CurShape { get; set; }

        public void ShowCurInfo()
        {
            Console.WriteLine("当前图像形状：{0}，图形颜色：{1}",this.CurShape.Name,this.CurColor.ColorName);
        }
    }
    #endregion


}
